namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class ImageInputFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ImageInput>()
                .DerivesFrom<Input>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("input")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            ImageInput expected = new ImageInput(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                AlternativeText = "alternative",
                Disabled = true,
                Language = "fr",
                ReadOnly = true,
                Size = 50,
                Source = new Uri("http://example.com/image.png"),
                TabIndex = 1,
                Value = "value"
            };

            string xml = "<input id='id' class='class' lang='fr' name='id' accesskey='a' alt='alternative' tabindex='1' disabled='disabled' readonly='readonly' size='50' type='image' value='value' src='http://example.com/image.png' />";
            ImageInput actual = xml.Deserialize<ImageInput>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<input type='image' />".Deserialize<ImageInput>());
        }

        [Fact]
        public void serialize()
        {
            ImageInput obj = new ImageInput(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                AlternativeText = "alternative",
                Disabled = true,
                Language = "fr",
                ReadOnly = true,
                Size = 50,
                Source = new Uri("http://example.com/image.png"),
                TabIndex = 1,
                Value = "value"
            };

            string xpath = "1=count(/input[@id='id'][@class='class'][@lang='fr'][@name='id'][@tabindex='1'][@disabled='disabled'][@accesskey='a'][@alt='alternative'][@readonly='readonly'][@size='50'][@type='image'][@value='value'][@src='http://example.com/image.png'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new ImageInput());
        }

        [Fact]
        public void ctor_Name()
        {
            Assert.NotNull(new ImageInput(new Name("id")));
        }

        [Fact]
        public void ctor_NameNull()
        {
            Assert.NotNull(new ImageInput(null));
        }

        [Fact]
        public void prop_Source()
        {
            Assert.True(new PropertyExpectations(typeof(ImageInput).GetProperty("Source"))
                .IsAutoProperty<Uri>()
                .Result);
        }

        [Fact]
        public void prop_Type()
        {
            Assert.True(new PropertyExpectations(typeof(ImageInput).GetProperty("Type"))
                .DefaultValueIs("image")
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            ImageInput expected = new ImageInput(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                AlternativeText = "alternative",
                Disabled = true,
                Language = "fr",
                ReadOnly = true,
                Size = 50,
                Source = new Uri("http://example.com/image.png"),
                TabIndex = 1,
                Value = "value"
            };

            string xml = "<input id='id' class='class' lang='fr' name='id' accesskey='a' alt='alternative' tabindex='1' disabled='disabled' readonly='readonly' size='50' type='image' value='value' src='http://example.com/image.png' />";
            ImageInput actual = new ImageInput().Deserialize("input", "image", xml) as ImageInput;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}